Repository navigation
Conversation
|
This repository now uses |
|
Hi @juan-vgv, since it's useful to display this info on pub.dev as well, it might be better to put this information in the readme of the package it concerns. At least However, leave it in the main README here as well |
| // ... | ||
| setUp(() { | ||
| CachedNetworkImageProvider.defaultCacheManager = _MockCacheManager(); | ||
| }); |
There was a problem hiding this comment.
Maybe good to mention that the mock needs a stub too:
when(() => cacheManager.getFileStream(
any(),
key: any(named: 'key'),
headers: any(named: 'headers'),
withProgress: any(named: 'withProgress'),
)).thenAnswer((_) => const Stream.empty());|
|
||
| However, when testing widgets that use it you might run into an error such as this: | ||
| ``` | ||
| Warning: At least one test in this suite creates an HttpClient. |
There was a problem hiding this comment.
When I ran it without a mock, the test failed on MissingPluginException from path_provider, and the HttpClient text only showed up as a warning. Quoting the exception would help people who search for it. The default is also only used when the widget gets no cacheManager:, so apps that pass their own need to fake that one instead.
✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)
Documentation update.
Testing is a fundamental part of software development and currently there are no official guidelines on how to thoroughly test widgets that contain an instance of
CachedNetworkImage.This PR aims to at least add some basic indication on where to start, but it's not exhaustive by any means.
If there're better ways of implementing these tests I'd be more than happy to know and update this PR accordingly. Also happy to write a more thorough dedicated testing guide with the support from someone on your team!
Thanks a bunch.
N/A
🆕 What is the new behavior (if this is a feature change)?
Nope
💥 Does this PR introduce a breaking change?
Nope
🐛 Recommendations for testing
N/A
📝 Links to relevant issues/docs
🤔 Checklist before submitting